<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let n = parseInt(prompt("请输入一个整数"));
        let scale = parseInt(prompt("请输入你想要转化的进制数"));
        let arr = [];


        function tab(a, b) {
            let c = a;
            let d = c % b;
            arr.push(d);
            while (c > 0) {
                c = Math.floor(c / b);
                // console.log(c);
                d = c % b;
                arr.push(d);
            }
            // 将得到的数组取0到最后下标减一的元素
            // 然后反向排列数组得到想要的组数
            let t = (arr.slice(0, (arr.length - 1))).reverse();
            // 将数组转化成字符串
            let sum = "";
            for (i = 0; i < t.length; i++) {
                sum = sum + t[i];
            }
            // 将字符串转化成数字
            sum = parseInt(sum);

            return sum;
        }

        console.log(tab(n, scale));
    </script>
</body>

</html>